package com.connector.base.message.model;

import com.alibaba.fastjson.JSONObject;
import com.connector.base.connection.Connection;
import com.connector.base.protocol.Command;
import com.connector.base.protocol.Packet;
import com.google.common.base.Charsets;

public class ChatMessage extends JsonBodyMessage
{
    private String userId;
    private String deviceId;
    private String type;
    private String contentType;
    private String receiver;
    private String body;
    private String date;
    private String dialogId;
    private String photo;
    private String otherText;
    private String fileName;
    private String userName;
    private String htmlText;
    private String msgUID;
    private String audioTimeLength;
    private Boolean readingStatus;
    private Boolean pcOrApp;

    public ChatMessage() {
    }

    public ChatMessage(final Packet packet, final Connection connection) {
        super(packet, connection);
    }

    public static Packet buildPacket(final String msg) {
        final Packet packet = new Packet();
        packet.setCmd(Command.CHAT.cmd);
        packet.setBodyLength(msg.length());
        packet.setType((byte)1);
        packet.setBody(msg.getBytes(Charsets.UTF_8));
        return packet;
    }

    @Override
    public void jsonToFields(final JSONObject jsonBody) {
        this.userId = (jsonBody.containsKey((Object)"userId") ? jsonBody.getString("userId") : null);
        this.deviceId = (jsonBody.containsKey((Object)"deviceId") ? jsonBody.getString("deviceId") : null);
        this.type = (jsonBody.containsKey((Object)"type") ? jsonBody.getString("type") : null);
        this.contentType = (jsonBody.containsKey((Object)"contentType") ? jsonBody.getString("contentType") : null);
        this.receiver = (jsonBody.containsKey((Object)"receiver") ? jsonBody.getString("receiver") : null);
        this.body = (jsonBody.containsKey((Object)"body") ? jsonBody.getString("body") : null);
        this.photo = (jsonBody.containsKey((Object)"photo") ? jsonBody.getString("photo") : null);
        this.otherText = (jsonBody.containsKey((Object)"otherText") ? jsonBody.getString("otherText") : null);
        this.date = (jsonBody.containsKey((Object)"date") ? jsonBody.getString("date") : null);
        this.dialogId = (jsonBody.containsKey((Object)"dialogId") ? jsonBody.getString("dialogId") : null);
        this.fileName = (jsonBody.containsKey((Object)"fileName") ? jsonBody.getString("fileName") : null);
        this.userName = (jsonBody.containsKey((Object)"userName") ? jsonBody.getString("userName") : null);
        this.htmlText = (jsonBody.containsKey((Object)"htmlText") ? jsonBody.getString("htmlText") : null);
        this.msgUID = (jsonBody.containsKey((Object)"msgUID") ? jsonBody.getString("msgUID") : null);
        this.audioTimeLength = (jsonBody.containsKey((Object)"audioTimeLength") ? jsonBody.getString("audioTimeLength") : null);
    }

    @Override
    public JSONObject fieldToJson() {
        final JSONObject resultObj = new JSONObject();
        resultObj.put("userId", (Object)this.userId);
        resultObj.put("deviceId", (Object)this.deviceId);
        resultObj.put("type", (Object)this.type);
        resultObj.put("contentType", (Object)this.contentType);
        resultObj.put("receiver", (Object)this.receiver);
        resultObj.put("body", (Object)this.body);
        resultObj.put("date", (Object)this.date);
        resultObj.put("dialogId", (Object)this.dialogId);
        resultObj.put("photo", (Object)this.photo);
        resultObj.put("otherText", (Object)this.otherText);
        resultObj.put("fileName", (Object)this.fileName);
        resultObj.put("userName", (Object)this.userName);
        resultObj.put("htmlText", (Object)this.htmlText);
        resultObj.put("msgUID", (Object)this.msgUID);
        resultObj.put("audioTimeLength", (Object)this.audioTimeLength);
        return resultObj;
    }

    public String getUserId() {
        return this.userId;
    }

    public String getDeviceId() {
        return this.deviceId;
    }

    public String getType() {
        return this.type;
    }

    public String getContentType() {
        return this.contentType;
    }

    public String getReceiver() {
        return this.receiver;
    }

    public String getBody() {
        return this.body;
    }

    public String getDate() {
        return this.date;
    }

    public String getDialogId() {
        return this.dialogId;
    }

    public String getPhoto() {
        return this.photo;
    }

    public String getOtherText() {
        return this.otherText;
    }

    public String getFileName() {
        return this.fileName;
    }

    public String getUserName() {
        return this.userName;
    }

    public String getHtmlText() {
        return this.htmlText;
    }

    public String getMsgUID() {
        return this.msgUID;
    }

    public String getAudioTimeLength() {
        return this.audioTimeLength;
    }

    public Boolean getReadingStatus() {
        return this.readingStatus;
    }

    public Boolean getPcOrApp() {
        return this.pcOrApp;
    }

    public void setUserId(final String userId) {
        this.userId = userId;
    }

    public void setDeviceId(final String deviceId) {
        this.deviceId = deviceId;
    }

    public void setType(final String type) {
        this.type = type;
    }

    public void setContentType(final String contentType) {
        this.contentType = contentType;
    }

    public void setReceiver(final String receiver) {
        this.receiver = receiver;
    }

    public void setBody(final String body) {
        this.body = body;
    }

    public void setDate(final String date) {
        this.date = date;
    }

    public void setDialogId(final String dialogId) {
        this.dialogId = dialogId;
    }

    public void setPhoto(final String photo) {
        this.photo = photo;
    }

    public void setOtherText(final String otherText) {
        this.otherText = otherText;
    }

    public void setFileName(final String fileName) {
        this.fileName = fileName;
    }

    public void setUserName(final String userName) {
        this.userName = userName;
    }

    public void setHtmlText(final String htmlText) {
        this.htmlText = htmlText;
    }

    public void setMsgUID(final String msgUID) {
        this.msgUID = msgUID;
    }

    public void setAudioTimeLength(final String audioTimeLength) {
        this.audioTimeLength = audioTimeLength;
    }

    public void setReadingStatus(final Boolean readingStatus) {
        this.readingStatus = readingStatus;
    }

    public void setPcOrApp(final Boolean pcOrApp) {
        this.pcOrApp = pcOrApp;
    }

    @Override
    public String toString() {
        return "ChatMessage(userId=" + this.getUserId() + ", deviceId=" + this.getDeviceId() + ", type=" + this.getType() + ", contentType=" + this.getContentType() + ", receiver=" + this.getReceiver() + ", body=" + this.getBody() + ", date=" + this.getDate() + ", dialogId=" + this.getDialogId() + ", photo=" + this.getPhoto() + ", otherText=" + this.getOtherText() + ", fileName=" + this.getFileName() + ", userName=" + this.getUserName() + ", htmlText=" + this.getHtmlText() + ", msgUID=" + this.getMsgUID() + ", audioTimeLength=" + this.getAudioTimeLength() + ", readingStatus=" + this.getReadingStatus() + ", pcOrApp=" + this.getPcOrApp() + ")";
    }
}
